
using OhioState.AssetManaged;
using OhioState.Graphics;
using OhioState.Graphics.Proxy;

using Tao.OpenGl;

namespace OhioState.Graphics.OpenGL
{
    public class SegmentHandler : TextureHandler
    {
        public SegmentHandler(IAssetManaged proxyObject)
            : base(proxyObject)
        {
        }
        protected override void createGLTexture()
        {
            _realTexture = new Texture3DGL(_textureProxy.Width, _textureProxy.Height, _textureProxy.Depth, _textureProxy.TexelType);
        }
        protected override void updateGLTexture()
        {
            Segment segment = _textureProxy as Segment;
            if (segment != null)
            {
                int xDim, yDim, zDim;
                byte[] byte_buffer;
                int format = TextureManager.PixelFormat[segment.TexelType.Format];
                int type = TextureManager.PixelBuffer[segment.TexelType.Type];
                switch (segment.TexelType.Type)
                {
                    case ByteFormat.BYTE:
                        byte_buffer = segment.GetTextureByte(out xDim, out yDim, out zDim);
                        Gl.glTexSubImage3D(Gl.GL_TEXTURE_3D, 0, 0, 0, 0,
                            xDim, yDim, zDim,
                            format, type, byte_buffer);
                        break;
                    //case ByteFormat.INT:
                    //    uint_buffer = segment.GetTextureInt(out xDim, out yDim, out zDim);
                    //    Gl.glTexSubImage3D(Gl.GL_TEXTURE_3D, 0, 0, 0, 0,
                    //        xDim, yDim, zDim,
                    //        format, type, uint_buffer);
                    //    break;
                    //case ByteFormat.SHORT:
                    //    byte_buffer = segment.GetTextureShort(out xDim, out yDim, out zDim);
                    //    Gl.glTexSubImage3D(Gl.GL_TEXTURE_3D, 0, 0, 0, 0,
                    //        xDim, yDim, zDim,
                    //        format, Gl.GL_UNSIGNED_BYTE, byte_buffer);
                    //    break;
                    //case ByteFormat.FLOAT:
                    //    float_buffer = segment.GetTextureFloat(out xDim, out yDim, out zDim);
                    //    Gl.glTexSubImage3D(Gl.GL_TEXTURE_3D, 0, 0, 0, 0,
                    //        xDim, yDim, zDim,
                    //        format, type, float_buffer);
                    //    break;
                }
                //Gl.glDisable(Gl.GL_TEXTURE_3D);
                
            }
        }
    }
}
